package 位运算;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/21 19:29
 */
public class L78 {
    public static void main(String[] args) {
        new L78().singleNumber(new int[]{3,3,3,4,4,4,5});
    }

    public List<List<Integer>> subsets(int[] nums) {
        return binaryBit(nums);
    }

    public static List<List<Integer>> binaryBit(int[] nums) {
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        for (int i = 0; i < (1 << nums.length); i++) {
            List<Integer> sub = new ArrayList<Integer>();
            for (int j = 0; j < nums.length; j++)
                if (((i >> j) & 1) == 1) sub.add(nums[j]);
            res.add(sub);
        }
        return res;
    }

    public  int singleNumber(int[] nums) {
        int[] counts = new int[32];
        for (int num : nums) {
            for (int j = 0; j < 32; j++) {
                counts[j] += num & 1;
                num >>>= 1;
            }
        }
        int res = 0, m = 3;
        for (int i = 0; i < 32; i++) {
            res <<= 1;
            int x = counts[31 - i] % m;
            res |= x;
        }
        return res;
    }
}

